<?php

/**
 * API：api文档
 */

namespace app\controller\api;

use app\BaseController;
use hg\apidoc\annotation as Apidoc;
use app\controller\Definitions;

#[Apidoc\Title("基础示例")]
class Doc extends BaseController
{
    #[
        Apidoc\Title("列表"),
        Apidoc\Method("GET"),
        Apidoc\Query(name:"name",type: "string",require: true,desc: "姓名"),
        Apidoc\Query(name:"age",type: "string",require: true,desc: "年龄"),
        Apidoc\Query(ref:[Definitions::class,"pagingParam"] ),
        Apidoc\Returned("url",type: "int",desc: "url"),
        Apidoc\Returned("method",type: "string",desc: "method"),
        Apidoc\Returned(name:"name",type: "string",require: true,desc: "姓名"),
        Apidoc\Returned(name:"age",type: "string",require: true,desc: "年龄"),
    ]
    public function list()
    {
        
        $data = [
            'url' => request()->url(),
            'method'=>request()->method(),
            'name' => request()->param('name'),
            'age' => request()->param('age'),
        ];
        return json($data);
    }

    //get请求-详情
    public function detail($id)
    {
        $data = [
            'url' => request()->url(),
            'method'=>request()->method(),
            'id' => $id,
        ];
        return json($data);
    }

    //post请求
    public function add()
    {
        $data = [
            'url' => request()->url(),
            'method'=>request()->method(),
            'name' => request()->param('name'),
            'age' => request()->param('age'),
        ];
        return json($data);
    }

    //put请求
    public function update()
    {
        $data = [
            'url' => request()->url(),
            'method'=>request()->method(),
            'name' => request()->param('name'),
            'age' => request()->param('age'),
        ];
        return json($data);
    }

    //delete请求
    public function delete($id)
    {
        $data = [
            'url' => request()->url(),
            'method'=>request()->method(),
            'id' => $id,
        ];
        return json($data);
    }
}
